#mapping-script
# -*- coding: ms949 -*-
import bots.transform as transform
import bots.usersys.mappings.utils as utils

def main(inn,out):
    
    ns1 = '{urn:kr:gov:kcs:data:standard:KCS_NoticeOfOmissionOfScheduledOverdueGoodsInformationSchemaModule:1:0:0}'
    ns2 = '{urn:kr:gov:kcs:common:standard:KCS_ReusableAggregateBusinessInformationEntitySchemaModule:1:0:0}'
    rootelement = ns1 + 'NoticeOfOmissionOfScheduledOverdueGoodsInformation'
    
    #Read from inn by XML order

    #NoticeOfOmissionOfScheduledOverdueGoodsInformation 
    ScheduledOverdueGoodsDate = inn.get({'BOTSID':rootelement,ns1+'ScheduledOverdueGoodsDate':None})
    CarriedInMeasure = inn.get({'BOTSID':rootelement,ns1+'CarriedInMeasure':None})
    CarriedInMeasure_measureUnitCode = inn.get({'BOTSID':rootelement,ns1+'CarriedInMeasure__measureUnitCode':None})
    
    #NoticeOfOmissionOfScheduledOverdueGoodsInformation/Document
    DocumentTypeCode = inn.get({'BOTSID':rootelement},{'BOTSID':ns1+'Document',ns2+'TypeCode':None})
    
    #NoticeOfOmissionOfScheduledOverdueGoodsInformation/ScheduledOverdueGoodsUCR
    ScheduledOverdueGoodsUCRIdentificationID = inn.get({'BOTSID':rootelement},{'BOTSID':ns1+'ScheduledOverdueGoodsUCR',ns2+'IdentificationID':None})
    
    #NoticeOfOmissionOfScheduledOverdueGoodsInformation/UCR
    UCRIdentificationID = inn.get({'BOTSID':rootelement},{'BOTSID':ns1+'UCR',ns2+'IdentificationID':None})
    
    #NoticeOfOmissionOfScheduledOverdueGoodsInformation/CarriedInGoodsPackaging
    CarriedInGoodsPackagingQuantity = inn.get({'BOTSID':rootelement},{'BOTSID':ns1+'CarriedInGoodsPackaging',ns2+'Quantity':None})
    
    #NoticeOfOmissionOfScheduledOverdueGoodsInformation/Warehouse
    WarehouseCodeID = inn.get({'BOTSID':rootelement},{'BOTSID':ns1+'Warehouse',ns2+'CodeID':None})
    
    #NoticeOfOmissionOfScheduledOverdueGoodsInformation/AssociatedTransportDocument
    AssociatedTransportDocumentReferenceID = inn.get({'BOTSID':rootelement},{'BOTSID':ns1+'AssociatedTransportDocument',ns2+'referenceID':None})
    
    out.ta_info['botskey'] = 'CUSINS-5IN-' + ScheduledOverdueGoodsUCRIdentificationID.strip()
    
    #Write to out by EDIFACT order
    
    out.put({'BOTSID':'UNH','0062':out.ta_info['reference']})
    out.put({'BOTSID':'UNH','S009.0065':'CUSINS'})
    out.put({'BOTSID':'UNH','S009.0052':'S'})
    out.put({'BOTSID':'UNH','S009.0054':'93A'})
    out.put({'BOTSID':'UNH','S009.0051':'KE'})
            
    out.put({'BOTSID':'UNH'},{'BOTSID':'BGM','C002.1001':DocumentTypeCode})
    out.put({'BOTSID':'UNH'},{'BOTSID':'BGM','1004':ScheduledOverdueGoodsUCRIdentificationID})
    
    out.put({'BOTSID':'UNH'},{'BOTSID':'DTM','C507.2005':'206','C507.2380':utils.edifactYYYYMMDD(ScheduledOverdueGoodsDate),'C507.2379':'102'})
    out.put({'BOTSID':'UNH'},{'BOTSID':'RFF','C506.1153':'XC','C506.1154':UCRIdentificationID})
    out.put({'BOTSID':'UNH'},{'BOTSID':'RFF'},{'BOTSID':'PAC','7224':CarriedInGoodsPackagingQuantity})
    out.put({'BOTSID':'UNH'},{'BOTSID':'RFF'},{'BOTSID':'MEA','6311':'WT','C174.6411':CarriedInMeasure_measureUnitCode,'C174.6314':CarriedInMeasure})
    out.put({'BOTSID':'UNH'},{'BOTSID':'RFF'},{'BOTSID':'LOC','3227':'18','C517.3225':WarehouseCodeID,'C517.1131':'129','C517.3055':'KCS'})
    out.put({'BOTSID':'UNH'},{'BOTSID':'RFF'},{'BOTSID':'DOC','C002.1001':'705','C503.1004':AssociatedTransportDocumentReferenceID})
    
    out.put({'BOTSID':'UNH'},{'BOTSID':'UNT','0074':out.getcount()+1})
    out.put({'BOTSID':'UNH'},{'BOTSID':'UNT','0062':out.ta_info['reference']}) 
    
